package cn.yitun.chat.yitunserverimcore.general.main.push.chat;

import cn.yitun.chat.yituncommonmessage.impl.HeadImpl;
import cn.yitun.chat.yituncommonmessage.push.PushMessage;
import cn.yitun.chat.yituncommonutil.YitunStringUtil;
import cn.yitun.chat.yitunservercommonlib.constant.ActionTypeConstant;
import cn.yitun.chat.yitunservercommonlib.dataentity.data.message.chat.Content;
import cn.yitun.chat.yitunservercommonlib.enums.control.push.group.GroupChatPushMethodEnum;
import cn.yitun.chat.yitunserverimcore.bridge.net.WriteHandler;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 群消息推送
 * 
 * @author: yitun
 * @date: 2016-08-26 9:21:41
 */
@Service
public class GroupChatPush {
	@Resource
	WriteHandler writeHandler;
	//1.3.102
	final String action = ActionTypeConstant.GROUP_CHAT_ACTION_PUSH;
	/**
	 * 推送群聊信息
	 * 
	 * @author yitun
	 * @date 2017-11-23 13:57:06
	 * @param key
	 * @param groupId
	 * @param userId
	 * @param content
	 * @param userIdList
	 */
	public void groupChat(Long key, Long groupId, Long userId, Content content, List<Long> userIdList) {
		PushMessage message = new PushMessage();
		message.bodyPut("groupId", groupId);
		message.bodyPut("userId", userId);
		message.bodyPut("content", content);
		message.bodyPut("messageKey", content.getKey());

		HeadImpl head = new HeadImpl();
		head.setAction(action);
		head.setMethod(GroupChatPushMethodEnum.GROUP_CHAT.getMethod());
		head.setKey(key);
		head.setTimestamp(System.currentTimeMillis());
		message.setHead(head);

		writeHandler.push(YitunStringUtil.toStrList(userIdList), message);
	}
}
